<?php
Yii::import('Cms.components.widgets.BaseCmsWidget');
class CmsImage extends BaseCmsWidget {
    
    protected $id;
    
    public function run(){
        $models = $this->getActiveDataProvider()->getData();
        if (count($models)){
            $this->id = $models[0]->id;
            return CHtml::image($models[0]->source, $models[0]->alt);
        }
    }
    
    // this widget does not have layout
    public function getSelectedLayout() {
        return null;
    }
    
    // return the url to edit text content
    public function getEditUrl($params = array()){
        $params['page_widget_id'] = $this->pageWidgetId;
        $params['id'] = $this->dataSettings['params'][':id'];
        
        return url('/Cms/widgets/cmsImage/update', $params);
    }
}